/*
 * Copyright 2002-2005 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package lib.jsonrpc;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * The Interface RPCService.
 * 
 * 
 * @author jay liu
 * @since 07.10.2010
 */
public interface RPCService {
	
	/**
	 * Dispatch http request to some method.
	 *
	 * @param req the req
	 * @param resp the resp
	 */
	void dispatch(HttpServletRequest req, HttpServletResponse resp);
	
	/**
	 * Gets the http request of this RPC invocation. (thread safe by thread local variable)
	 *
	 * @return the request
	 */
	HttpServletRequest getRequest();
	
	/**
	 * Gets the http response of this RPC invocation. (thread safe by thread local variable)
	 *
	 * @return the response
	 */
	HttpServletResponse getResponse();
	
	/**
	 * Gets the service name for debug
	 *
	 * @return the service name
	 */
	String getServiceName();
	
	/**
	 * Gets the object factory for new parameter objects or return value. (json<->java)
	 *
	 * @return the object factory
	 */
	public ObjectFactory getObjectFactory();
	
	/**
	 * Before invoke RPC method.
	 *
	 * @param method the method
	 * @param args the args
	 */
	void beforeInvoke(Method method, Object[] args);
	
	/**
	 * After invoke RPC method plus return value object.
	 *
	 * @param method the method
	 * @param args the args
	 * @param retObj the ret obj
	 */
	void afterInvoke(Method method, Object[] args, Object retObj);
}
